package com.jhgsys.internal.hazard.service.impl;

import com.jhgsys.internal.hazard.entity.HazardReportAuditRecord;
import com.jhgsys.internal.hazard.mapper.HazardReportAuditRecordMapper;
import com.jhgsys.internal.hazard.service.IHazardReportAuditRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 隐患报告审核记录 Service实现
 *
 * @author wanghw
 * @date 2024-08-20 09:23:12
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class HazardReportAuditRecordServiceImpl extends ServiceImpl<HazardReportAuditRecordMapper, HazardReportAuditRecord> implements IHazardReportAuditRecordService {

    /**
     * 查询（分页）
     * @author wanghw
     * @date 2024-08-20 09:23:12
     * @param request QueryRequest
     * @param hazardReportAuditRecord hazardReportAuditRecord
     * @return IPage<HazardReportAuditRecord>
    */
    @Override
    public IPage<HazardReportAuditRecord> findHazardReportAuditRecordPage(QueryRequest request, HazardReportAuditRecord hazardReportAuditRecord) {
        LambdaQueryWrapper<HazardReportAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardReportAuditRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<HazardReportAuditRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author wanghw
     * @date 2024-08-20 09:23:12
     * @param hazardReportAuditRecord hazardReportAuditRecord
     * @return List<HazardReportAuditRecord>
     */
    @Override
    public List<HazardReportAuditRecord> findHazardReportAuditRecordList(HazardReportAuditRecord hazardReportAuditRecord) {
	    LambdaQueryWrapper<HazardReportAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardReportAuditRecord::getDeletedFlg, 0);
        queryWrapper.eq(HazardReportAuditRecord::getReportId, hazardReportAuditRecord.getReportId());
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author wanghw
    * @date 2024-08-20 09:23:12
    * @param id
    * @return HazardReportAuditRecord
    */
    @Override
    public HazardReportAuditRecord findHazardReportAuditRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author wanghw
     * @date 2024-08-20 09:23:12
     * @param hazardReportAuditRecord hazardReportAuditRecord
     */
    @Override
    @Transactional
    public void createHazardReportAuditRecord(HazardReportAuditRecord hazardReportAuditRecord) {
        hazardReportAuditRecord.setCreatedTime(new Date());
        this.save(hazardReportAuditRecord);
    }

    /**
     * 修改
     * @author wanghw
     * @date 2024-08-20 09:23:12
     * @param hazardReportAuditRecord hazardReportAuditRecord
     */
    @Override
    @Transactional
    public void updateHazardReportAuditRecord(HazardReportAuditRecord hazardReportAuditRecord) {
        hazardReportAuditRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(hazardReportAuditRecord);
    }

    /**
     * 逻辑删除
     * @author wanghw
     * @date 2024-08-20 09:23:12
     * @param hazardReportAuditRecord hazardReportAuditRecord
     * @param hazardReportAuditRecordIds hazardReportAuditRecordIds
     */
    @Override
    @Transactional
    public void deleteHazardReportAuditRecord(HazardReportAuditRecord hazardReportAuditRecord,String hazardReportAuditRecordIds) {
        List<String> list = Arrays.asList(hazardReportAuditRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(hazardReportAuditRecord,new LambdaQueryWrapper<HazardReportAuditRecord>().in(HazardReportAuditRecord::getReportAuditRecordId,list));
	}

    /**
    * 物理删除
    * @author wanghw
    * @date 2024-08-20 09:23:12
    * @param hazardReportAuditRecordIds hazardReportAuditRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeleteHazardReportAuditRecord(String hazardReportAuditRecordIds) {
        List<String> list = Arrays.asList(hazardReportAuditRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardReportAuditRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(HazardReportAuditRecord::getReportAuditRecordId,list);
        this.remove(wapper);
    }
}
